<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link href="/static/layui/css/layui.css" rel="stylesheet">
		<script src="http://code.jquery.com/jquery-latest.js"></script>
		<!-- 引入 layui.js -->
		<script src="/static/layui/layui.js"></script>
	</head>
	<body>
		<form class="layui-form layui-form-pane" style="padding: 20px;" action="">
			<input type="hidden" name="id" value="{$res.id}" />
			<input type="hidden" name="username" value="{$res.username}" />
			<div class="layui-form-item">
				<label class="layui-form-label">单据编号</label>
				<div class="layui-input-block">
					<input type="text" name="document_number" id="djbh" autocomplete="off" placeholder="请输入单据编号" lay-verify="required" class="layui-input" disabled value="{$res.document_number}">
				</div>
			</div>
		
			<div class="layui-form-item">
				<label class="layui-form-label">报销用途</label>
				<div class="layui-input-block">
					<input type="text" name="purpose" autocomplete="off" placeholder="请输入报销用途" lay-verify="required"
						class="layui-input" value="{$res.purpose}">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">单价</label>
					<div class="layui-input-block">
						<input type="text" name="unit_price" placeholder="请输入单价" autocomplete="off"
							lay-verify="required" class="layui-input" id="number1" value="{$res.unit_price}">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">数量</label>
					<div class="layui-input-inline">
						<input type="number" name="quantity" placeholder="请输入数量" autocomplete="off"
							lay-verify="required" class="layui-input" id="number2" value="{$res.quantity}">
					</div>
				</div>
			</div>
			<input type="hidden" name="total_amount" id="sum" value="{$res.total_amount}" />
			<div class="layui-form-item">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<input type="text" name="remarks" autocomplete="off" placeholder="请输入备注" lay-verify="required"
						class="layui-input" value="{$res.remarks}">
				</div>
			</div>
			<div class="layui-upload-drag" style="display: block;" id="upload-demo-drag">
				<i class="layui-icon layui-icon-upload"></i>
				<div>点击上传，或将文件拖拽到此处<br />允许上传的文件后缀：png | jpg</div>
				<div class="layui-hide" id="upload-demo-preview">
					<hr> <img src="" alt="上传成功后渲染" style="max-width: 100%">
				</div>
			</div>
			<div class="layui-form-item" style="margin-top: 30px;">
				<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-edit" id="btn">添加</button>
			</div>
		</form>
		<script>
		$(document).ready(function() {
		   $('#number1, #number2').blur(function(){
		      var num1 = parseFloat($('#number1').val()) || 0;
		      var num2 = parseFloat($('#number2').val()) || 0;
		      var result = num1 * num2;
		      $('#sum').val(result.toFixed(2)); // 保留两位小数
			});
		});
		layui.use(function() {
				var form = layui.form;
				var layer = layui.layer;
				var upload = layui.upload;
				upload.render({
				    elem: '#upload-demo-drag',
				    url: '{:url("Reimbursement/reimbursementuploadfie")}', // 实际使用时改成您自己的上传接口即可。
					auto:false,
					bindAction:'#btn',
					accept:'file',
					exts:'png|jpg',
					done: function(res){
					      if (res.code == 1) {
					      	layer.msg(res.msg);
					      }
					}
				  }); 
				  $.ajax({
				  	url: '{:url("Reimbursement/reimbursementedit")}',
				  	type: 'get',
				  	/* data:data.id, */
				  	dataType: 'json',
				  	success: function(res) {
				  		if (res.code == 200) {
				  			layer.msg(res.msg, {
				  				time: 500
				  			});
				  		} else {
				  			layer.msg(res.msg);
				  		}
				  	}
				  });
				form.on('submit(demo-edit)', function(data) {
					var field = data.field;
					var index = parent.layer.getFrameIndex(window.name); 
					
					/* layer.alert(JSON.stringify(field), {
					      title: '当前填写的字段值'
					    }); */
					$.ajax({
						url:'{:url("Reimbursement/reimbursementeditdata")}',
						type:'post',
						data:field,
						dataType:'json',
						success: function(res){
						    if (res.code == 200){
								layer.msg(res.msg,{time:500},function(){
									/* parent.layui.table.reload('tablea'); */
									window.parent.location.reload();
									parent.layer.close(index);
									
								});
							}else{
								layer.msg(res.msg);
							}
						}
					});
					return false; // 阻止默认 form 跳转
				});
		});
		</script>
	</body>
</html>